<?php
/**
 * Enter description here...
 *
 * @package if
 * @subpackage module.helper.controllers
 * @since 1.0
 */
class IfHelperTemplateController extends IHelperController {
	function doIndex() {
		$tpl = xn("tpl");
		$this->exists = is_file($tpl);
		if ($this->exists) {
			$this->contents = file_get_contents($tpl);
		}
		else {
			$this->contents = "";
		}
		
		if ($this->request()->isPost()) {
			$source = xn("source");
			$this->contents = $source;
			$writer = new IFileWriter(new IFile($tpl));
			$writer->write($source, true);
			$writer->close();
			$this->exists = true;
			if (x("save_and_refresh")) {
				echo "<script>window.parent.location.reload();</script>";
				return 1;
			}
		}
	}
	
	function doDelete() {
		$tpl = xn("tpl");
		if (is_file($tpl)) {
			@unlink($tpl);
		}
		$this->redirect("index", null, array(
			"tplo" => $tpl
		));
	}
}

?>